using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 工序控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ProcessController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public ProcessController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取工序列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<ProcessDto>>> GetProcesses([FromQuery] ProcessQueryDto query)
        {
            return await _consoleService.GetProcessesAsync(query);
        }

        /// <summary>
        /// 获取工序详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<ProcessDto>> GetProcess(int id)
        {
            return await _consoleService.GetProcessAsync(id);
        }

        /// <summary>
        /// 创建工序
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<ProcessDto>> CreateProcess([FromBody] ProcessDto dto)
        {
            return await _consoleService.CreateProcessAsync(dto);
        }

        /// <summary>
        /// 更新工序
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<ProcessDto>> UpdateProcess([FromBody] ProcessDto dto)
        {
            return await _consoleService.UpdateProcessAsync(dto);
        }

        /// <summary>
        /// 删除工序
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteProcess(int id)
        {
            return await _consoleService.DeleteProcessAsync(id);
        }
    }
} 